package com.example.demo.jpa.product;

import com.example.demo.jpa.product.domain.FinancialProduct;
import com.example.demo.jpa.product.dto.FinancialProductCommand;
import com.example.demo.jpa.product.dto.FinancialProductDTO;
import com.example.demo.jpa.product.repo.FinancialProductRepository;
import com.example.demo.jpa.product.service.FinancialProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class FinancialProductController {

    @Autowired
    private FinancialProductService financialProductService;

    @GetMapping("/{id}")
    public FinancialProductDTO getFinancialProductById(@PathVariable Long id){
        return financialProductService.findFinancialProductByID(id);
    }
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public FinancialProductDTO createFinancialProduct(@RequestBody FinancialProductCommand financialProductCommand){
        return financialProductService.createFinancialProduct(financialProductCommand);
    }
    @PutMapping("/{id}")
    public FinancialProductDTO updateFinancialProduct(@PathVariable Long id, @RequestBody FinancialProductCommand financialProductCommand){
        return  financialProductService.updateFinancialProduct(id,financialProductCommand);
    }
    @DeleteMapping("/{id}")
    public void deleteFinancialProduct(@PathVariable long id){
        financialProductService.deleteFinancialProductById(id);
    }

}
